#include <gtk/gtk.h>
#include <webkit2/webkit2.h>

static void on_load_changed(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data) {
    gboolean loaded = webkit_web_view_is_loading(webView);
    if (loaded) {
        g_print("Loading...\n");
    } else {
        g_print("Load Complete!\n");
    }
}

int main(int argc, char** argv) {
    gtk_init(&argc, &argv);

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "My Browser");
    gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));
    g_signal_connect(webView, "notify::is-loading", G_CALLBACK(on_load_changed), NULL);

    //webkit_web_view_load_uri(webView, "https://www.example.com");
    //webkit_web_view_load_uri(webView, "http://www.baidu.com");
    webkit_web_view_load_uri(webView, "http://192.168.1.83");

    gtk_widget_grab_focus(GTK_WIDGET(webView));
    gtk_widget_show_all(window);

    gtk_main();
    return 0;
}
